/*
 * rtp.h
 *
 *  Created on: 2017年8月11日
 *      Author: hxh
 */

#ifndef RTSPCLIENT_RTP_H_
#define RTSPCLIENT_RTP_H_

// 500K 应该够了
#define MAX_RTP_BUFFER 1024*1000
typedef void * HANDLE;
#define __PACKED__        __attribute__ ((__packed__))
// 小端格式代码
typedef unsigned int HI_U32;

typedef enum
{
	RTSP_VIDEO=0,
	RTSP_VIDEOSUB=1,
	RTSP_AUDIO=2,
	RTSP_YUV422=3,
	RTSP_RGB=4,
	RTSP_VIDEOPS=5,
	RTSP_VIDEOSUBPS=6
}enRTSP_MonBlockType;

struct _RTP_FIXED_HEADER
{
    unsigned char version:2;        /**//* expect 2 */
    unsigned char padding:1;        /**//* expect 0 */
    unsigned char extension:1;        /**//* expect 1, see RTP_OP below */
    unsigned char csrc_len:4;        /**//* expect 0 */
    /**//* byte 0 */
    /**//* bytes 2, 3 */
    /**//* byte 1 */
    unsigned char marker:1;        /**//* expect 1 */
    unsigned char payload:7;        /**//* RTP_PAYLOAD_RTSP */
    unsigned short seq_no;
    /**//* bytes 4-7 */
    HI_U32 timestamp;
    /**//* bytes 8-11 */
    HI_U32 ssrc;            /**//* stream number is used here. */
} __PACKED__;

typedef struct _RTP_FIXED_HEADER RTP_FIXED_HEADER;

struct _NALU_HEADER
{
    //byte 0
	unsigned char TYPE:5;
    unsigned char NRI:2;
	unsigned char F:1;
}__PACKED__; /**//* 1 BYTES */

typedef struct _NALU_HEADER NALU_HEADER;

struct _FU_INDICATOR
{
    // byte 0
    unsigned char TYPE:5;
	unsigned char NRI:2;
	unsigned char F:1;
}__PACKED__; /**//* 1 BYTES */

typedef struct _FU_INDICATOR FU_INDICATOR;

struct _FU_HEADER
{
   	 //byte 0
    unsigned char TYPE:5;
	unsigned char R:1;
	unsigned char E:1;
	unsigned char S:1;
} __PACKED__; /**//* 1 BYTES */
typedef struct _FU_HEADER FU_HEADER;

struct _AU_HEADER
{
    //byte 0, 1
    unsigned short au_len;
    //byte 2,3
    unsigned  short frm_len:13;
    unsigned char au_index:3;
} __PACKED__; /**//* 1 BYTES */
typedef struct _AU_HEADER AU_HEADER;

typedef enum tagNALU_E{
	NALU_SIGNEL,	// 单片包, 标准的NALU包
	NALU_MUTIL,		// 聚合包	// 一个包里有多个分片内容
	NALU_SLICE		// 分片包	// 多个小包拼接成大包
}NALU_E;

#define SLICE_NORMAL	0	// 常规单包
#define SLICE_START 1		// 多包开始
#define SLICE_MID	2		// 多包中包
#define SLICE_END	3		// 多包尾包

#define MAGIC_NUM	0xabcd1234
#define RTP_INVALID( obj ) ( obj->magic != MAGIC_NUM )

typedef struct RTP_PACK
{
	unsigned int magic;
	// 包序，没啥用
	int PreSeq;
	// 存放每次收到的RTP包
	char *buf;
	// 每次收到RTP包的时候都会计入offset偏移值里
	int offset;
	// 可以发送出去的帧buf
	char *frame;
	// 帧的长度，该frame里可能有多个小的帧信息
	int frame_offset;
	int size;
	// 本地包是否已经满了，满了的话在次进入时要重设偏移位置
	int hasFull;
	//这次收到的包类型
	char type;
	HI_U32 timestamp;	// 每个包的timestamp，没啥用
}RTP_PACK_S;

#endif /* RTSPCLIENT_RTP_H_ */
